﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
using Bots.BGBuddy.Helpers;
using Styx;
using System.Windows.Media;
using Styx.Common;
using Styx.Common.Helpers;
using Styx.CommonBot;

using Styx.CommonBot.POI;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.Pathing;
using Styx.Plugins;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.TreeSharp;
using System.Diagnostics;


namespace Survivalist
{
    public partial class Classname : CombatRoutine
    {
        public override sealed string Name { get { return "Survival Hunter v2.3.8"; } }

        public override WoWClass Class { get { return WoWClass.Hunter; } }

        private static LocalPlayer Me { get { return StyxWoW.Me; } }

        private string petName = string.Empty;

        public override bool WantButton { get { return true; } }

        private void slog(string format, params object[] args) //use for slogging
        {
            Logging.Write(format, args);
        }

        public override void OnButtonPress()
        {
            Logger.Write(Colors.Yellow, "Config opened!");
            Survivalist.Form1 myConfig = new Survivalist.Form1();
            myConfig.ShowDialog();
        }

        public override void Initialize()
        {
            Updater.CheckForUpdate();
        }

        public static void Sleep(int millisecondsTimeout) { }

        private static Stopwatch petPresenceTimer = new Stopwatch();

        private static Stopwatch RapidFireTimer = new Stopwatch();

        private static Stopwatch pullTimer = new Stopwatch();

        private static Stopwatch fightTimer = new Stopwatch();

        private static Stopwatch moveTimer = new Stopwatch();

        private static ulong lastGuid = 0;

        double shotRange = SpellManager.Spells["Auto Shot"].MaxRange - 1;

        private double targetDistance
        {
            get
            {
                return Me.GotTarget ? Me.CurrentTarget.Distance : uint.MaxValue - 1;
            }
        }
        private string misDirectionAt
        {
            get
            {
                if (SurvivalistSettings.myPrefs.Misdirection == "pet")
                {
                    return "RunMacroText('/cast [@pet,exists] Misdirection');";
                }
                else return "RunMacroText('/cast [@focus,exists] Misdirection');";
            }
        }
        public static uint PlayerCountBuff(string name)
        {
            return GetAuraStack(Me, name, true);

        }
        public static uint TargetCountDebuff(string name)
        {
            return GetAuraStack(Me.CurrentTarget, name, true);
        }
        public static uint GetAuraStack(WoWUnit unit, string auraName, bool fromMyAura)
        {
            if (unit != null)
            {
                WoWAura aura;
                if (unit.Auras.TryGetValue(auraName, out aura))
                {
                    var returnvalue = (!fromMyAura || aura.CreatorGuid == Me.Guid) && aura.StackCount > 0;
                    return returnvalue ? aura.StackCount : 0;
                }
                return 0;
            }
            return 0;
        }

        #region CC_Begin

        public override bool NeedRest { 
            get 
            {
                MendPet();
                if (Me.HealthPercent <= 60)
                {
                    Styx.CommonBot.Rest.Feed();
                }
                return false; 
            } 
        }

        public override void Rest() { }

        #endregion

        #region Pull

        public override void Pull() 
        {
            if (!SurvivalistSettings.myPrefs.DisableAllMovement)
            {
                if (Me.CurrentTarget.Guid != lastGuid)
                {
                    fightTimer.Reset();
                    lastGuid = Me.CurrentTarget.Guid;
                    slog("Killing " + Me.CurrentTarget.Name + " at distance " + System.Math.Round(targetDistance).ToString() + ".");
                    pullTimer.Reset();
                    pullTimer.Start();

                }
                else
                {
                    if (pullTimer.ElapsedMilliseconds > 30 * 1000)
                    {
                        slog("Cannot pull " + Me.CurrentTarget.Name + " now.  Blacklist for 3 minutes.");
                        Styx.CommonBot.Blacklist.Add(Me.CurrentTarget.Guid, System.TimeSpan.FromMinutes(3));
                    }
                }
                if (Me.CurrentTarget.Distance > shotRange)
                {
                    Navigator.MoveTo(attackPoint);

                    int i = 0;
                    while (i < 8 && Me.Location.Distance(attackPoint) > 1)
                    {
                        if (Me.Combat)
                        {
                            Logging.Write("Combat has started.  Abandon pull.");
                            break;
                        }

                        Sleep(250);
                        ++i;
                    }

                    return;
                }
                else
                {
                    slog("Starting attack");
                    if (Me.IsMoving)
                    {
                        WoWMovement.MoveStop();
                    }

                    if (Me.GotTarget && Me.GotAlivePet)
                    {
						Me.CurrentTarget.Face();
                        Lua.DoString(misDirectionAt);
                        SerpentSting();
                        if (!Me.Pet.IsAutoAttacking)
                        {
                            Lua.DoString("PetAttack()");
                        }
                    }
                }
            }
        }

        #endregion

        #region Pull Buffs

        public override bool NeedPullBuffs { get { return false; } }

        public override void PullBuff() { }

        #endregion

        #region Pre Combat Buffs

        public override bool NeedPreCombatBuffs
        {
            get
            {
                CallPet();
                RevivePet();
                Aspect();
                return false;
            }
        }

        public override void PreCombatBuff()
        {
            return;
        }

        #endregion

        #region Combat Buffs

        public override bool NeedCombatBuffs { get { return false; } }

        public override void CombatBuff() { }

        #endregion

        #region Heal

        public override bool NeedHeal { get { return false; } }

        public override void Heal() { }

        #endregion

        #region Falling

        public void HandleFalling() { }

        #endregion

        #region Combat
        public override void Combat()
        {
            if(!Me.GotTarget && (Me.Combat || Me.Pet.Combat))
            {
                Me.Pet.CurrentTarget.Target();
            }
            if (!SurvivalistSettings.myPrefs.DisableAllMovement && !Me.ActiveAuras.ContainsKey("Feign Death"))
            {
                    if (Me.CurrentTarget.Distance > shotRange)
                    {
                        Navigator.MoveTo(attackPoint);
                        return;
                    }
                    if (Me.IsMoving)
                    {
                        WoWMovement.MoveStop();
                    }
                    Me.CurrentTarget.Face();
                    CallPet();
                    RevivePet();
                    FeignDeath();
                    Tier4();
                    Tier5();
                    Tier6();
                    UseTrinket1();
                    UseTrinket2();
                    Stampede();
                    MendPet();
                    MisDirection();
                    SerpentSting();
                    HuntersMark();
                    RapidFire();
                    Racial();
                    KillShot();
                    BlackArrow();
                    ExplosiveShot();
                    CobraShot();
                    ArcaneShot();
                    MultiShot();
                    newExplosiveTrap();
                    Readiness();
                
            }
            if (SurvivalistSettings.myPrefs.DisableAllMovement && !Me.ActiveAuras.ContainsKey("Feign Death")) 
            {  
                CallPet();
                RevivePet();
                HealthStone();
                FeignDeath();
                LifeSpirit();
                Tier4();
                Tier5();
                Tier6();
                UseTrinket1();
                UseTrinket2();
                Stampede();
                MendPet();
                MisDirection();
                SerpentSting();
                HuntersMark();
                RapidFire();
                Racial();
                KillShot();
                BlackArrow();
                ExplosiveShot();
                CobraShot();
                ArcaneShot();
                MultiShot();
                ExplosiveTrap();
                Readiness();
            }
        }
        #endregion Combat

        #region Hunter Skills
        private void AutoAttack()
        {
            if (!Me.IsAutoAttacking)
            {
                Lua.DoString("StartAttack()");
            }

        }
        public bool Readiness()
        {
            if (SpellManager.CanCast("Readiness") && !SpellManager.GlobalCooldown && RapidFireTimer.ElapsedMilliseconds > 30000)
            {
                RapidFireTimer.Stop();
                SpellManager.Cast("Readiness");
                Logging.Write(Colors.Crimson,">>> Readiness <<<");
            }
            return false;
        }
        public bool RapidFire()
        {
            if (SpellManager.CanCast("Rapid Fire") && !SpellManager.GlobalCooldown && (GeefSajette() || SurvivalistSettings.myPrefs.AlwaysRapidFire))
            {
                RapidFireTimer.Reset();
                RapidFireTimer.Start();
                SpellManager.Cast("Rapid Fire");
                Logging.Write(Colors.Crimson, ">>> Rapid Fire <<<");
                return true;
            }
            return false;
        }
        public bool Stampede()
        {
            if (SpellManager.CanCast("Stampede") && !SpellManager.GlobalCooldown && GeefSajette())
            {
                SpellManager.Cast("Stampede");
                Logging.Write("Stampede");
                return true;
            }
            return false;
        }
        public bool Aspect()
        {
            if (SpellManager.CanCast("Aspect of the Iron Hawk") && !Me.HasAura("Aspect of the Iron Hawk") && !Me.Mounted)
            {
                SpellManager.Cast("Aspect of the Iron Hawk");
                Logger.Write(Colors.Yellow,"Aspect of the Iron Hawk");
                return true;
            }
             
            return false;
        }
        public bool HuntersMark()
        {
            if (SpellManager.CanCast("Hunter's Mark") && SurvivalistSettings.myPrefs.MarkedForDeath == false 
                && !Me.CurrentTarget.HasAura("Hunter's Mark"))
            { 
                SpellManager.Cast("Hunter's Mark");
                Logging.Write(Colors.Orange, "Hunter's Mark");
                StyxWoW.SleepForLagDuration();
                return true;
            }
            return false;
        }
        public bool SerpentSting()
        {
            if(SpellManager.CanCast("Serpent Sting") && !Me.CurrentTarget.HasAura("Serpent Sting"))
            { 
                SpellManager.Cast("Serpent Sting");
                Logging.Write(Colors.Orange, "Serpent Sting");
                StyxWoW.SleepForLagDuration();
                return true;
            }
            return false;
        }
        public bool ExplosiveTrap()
        {
            if (SpellManager.CanCast("Explosive Trap") && !SpellManager.GlobalCooldown && Adds())
            {
                if (!Me.HasAura("Trap Launcher"))
                {
                    if (CastSpell("Trap Launcher"))
                    {
                        Logger.Write(Colors.PaleGreen, ">> Trap Launcher Activated! <<");
                    }
                }
                else if (Me.HasAura("Trap Launcher"))
                { 
                    Lua.DoString("CastSpellByName('Explosive Trap');");
                    {
                        SpellManager.ClickRemoteLocation(StyxWoW.Me.CurrentTarget.Location);
                        Logger.Write(Colors.PaleGreen, ">> Explosive Trap Launched! <<");
                    }
                }
            }
            return false;
        }
        public bool newExplosiveTrap()
        {
            if (SpellManager.Spells["Explosive Trap"].CooldownTimeLeft.TotalSeconds < 1
                && !Me.IsChanneling && Me.HasAura("Trap Launcher") && (Adds() || GeefSajette()))
            {
                Lua.DoString("CastSpellByName('Explosive Trap');");
                {
                    SpellManager.ClickRemoteLocation(StyxWoW.Me.CurrentTarget.Location);
                    Logger.Write(Colors.Yellow, ">> Explosive Trap <<");
                }
                return true;
            }
            return false;
        }
        public bool MultiShot()
        {
            if (SpellManager.CanCast("Multi-Shot")
                && !SpellManager.GlobalCooldown
                && SurvivalistSettings.myPrefs.useMultiShot == true
                && Adds())
            {
                Lua.DoString(misDirectionAt);
                SpellManager.Cast("Multi-Shot");
                Logging.Write(Colors.Salmon, "Misdirection with Multi-Shot");
                return true;
            }
            return false;
        }
        public bool CobraShot()
        {
            if (SpellManager.CanCast(77767) && Me.Level >= 81 
                && Me.CurrentFocus <= 45 
                && !SpellManager.GlobalCooldown )
            { 
                SpellManager.Cast(77767);
                Logging.Write(Colors.Azure, "Cobra Shot");
                return true;
            }
            else if (SpellManager.CanCast("Steady Shot") 
                && Me.Level < 81 
                && Me.CurrentFocus <= 45 
                && !SpellManager.GlobalCooldown)
            { 
                SpellManager.Cast("Steady Shot");
                Logging.Write(Colors.Yellow, "Steady Shot");
                return true;
            }
            return false;
        }
        public bool ArcaneShot()
        {
            if (SpellManager.CanCast("Arcane Shot") && Me.CurrentFocus >= 65 && !Adds())
            { 
                SpellManager.Cast("Arcane Shot");
                Logging.Write(Colors.Yellow, "Arcane Shot");
                return true;
            }
            return false;
        }
        public bool ExplosiveShot()
        {
            if (SpellManager.CanCast("Explosive Shot") && !SpellManager.GlobalCooldown && !Adds())
            { 
                SpellManager.Cast("Explosive Shot");
                Logging.Write(Colors.Yellow, "Explosive Shot");
                return true;
            }
            return false;
        }
        public bool BlackArrow()
        {
            if (SpellManager.CanCast("Black Arrow") && !SpellManager.GlobalCooldown && !Adds() && !Me.CurrentTarget.HasAura("Black Arrow")) 
            { 
                SpellManager.Cast("Black Arrow");
                Logging.Write(Colors.Yellow, "Black Arrow");
                return true;
            }
            return false;
        }
        public bool KillShot()
        {
            if (SpellManager.CanCast("Kill Shot") && !SpellManager.GlobalCooldown && Me.CurrentTarget.HealthPercent < 20)
            { 
                SpellManager.Cast("Kill Shot");
                Logging.Write(Colors.Yellow, "Kill Shot");
                return true;
            }
            return false;
        }
        public bool Tier6()
        {
            string myTalent = SurvivalistSettings.myPrefs.Tier6;
            if (SpellManager.CanCast(myTalent) && !SpellManager.GlobalCooldown && GeefSajette())
            { 
                SpellManager.Cast(myTalent);
                Logging.Write(Colors.Yellow, myTalent);
                return true;
            }
            else if (SpellManager.CanCast(myTalent) && !SpellManager.GlobalCooldown && SurvivalistSettings.myPrefs.UseNotTier6OnNormalMobs == false)
            { 
                SpellManager.Cast(myTalent);
                Logging.Write(Colors.Yellow, myTalent);
                return true;
            }
            return false;
        }
        public bool Tier5()
        {
            string myTalent = SurvivalistSettings.myPrefs.Tier5;
            if (SpellManager.CanCast(myTalent) && !SpellManager.GlobalCooldown && GeefSajette())
            { 
                SpellManager.Cast(myTalent);
                Logging.Write(Colors.Yellow, myTalent);
                return true;
            }
            else if (SpellManager.CanCast(myTalent) && !SpellManager.GlobalCooldown && SurvivalistSettings.myPrefs.UseNotTier5OnNormalMobs == false)
            { 
                SpellManager.Cast(myTalent);
                Logging.Write(Colors.Yellow, myTalent);
                return true;
            }
            return false;
        }
        public bool Tier4()
        {
            string myTalent = SurvivalistSettings.myPrefs.Tier4;
            if (SpellManager.CanCast(myTalent) && !SpellManager.GlobalCooldown && GeefSajette())
            { 
                SpellManager.Cast(myTalent);
                Logging.Write(Colors.Yellow, myTalent);
                return true;
            }
            else if (SpellManager.CanCast(myTalent) && !SpellManager.GlobalCooldown && SurvivalistSettings.myPrefs.UseNotTier4OnNormalMobs == false)
            { 
                SpellManager.Cast(myTalent);
                Logging.Write(Colors.Yellow, myTalent);
                return true;
            }
            return false;
        }
        public bool FeignDeath()
        {
            if (Me.CurrentTarget.ThreatInfo.RawPercent > 80
                && Me.CurrentTarget.CurrentTargetGuid == Me.Guid
                && (Me.CurrentTarget.IsCasting
                || Me.CurrentTarget.Distance < 5 && Me.HealthPercent <= 40))
            {
                if (SpellManager.CanCast("Feign Death"))
                {
                    SpellManager.Cast("Feign Death");
                    Logging.Write(Colors.Aqua, ">> Aggro'ed, Feign Death <<");
                    Sleep(10000);
                    KeyboardManager.KeyUpDown(' ');
                    return true;
                }
            }
            return false;
        }
        public bool MisDirection()
        {
            if (SpellManager.CanCast("Misdirection"))
            {
                if (SurvivalistSettings.myPrefs.Misdirection == "pet" 
                    && Me.GotAlivePet 
                    && Me.CurrentTarget.CurrentTargetGuid == Me.Guid 
                    && !Me.ActiveAuras.ContainsKey("Misdirection")
                    && Me.CurrentTarget.ThreatInfo.RawPercent > 75)
                     
                {
                    Lua.DoString("RunMacroText('/cast [@pet,exists] Misdirection');");
                    {
                        Logging.Write(Colors.Aqua, ">> Misdirection on Pet <<");
                        return true;
                    }
                }
                else if (SurvivalistSettings.myPrefs.Misdirection == "focus" 
                    && Me.FocusedUnit != null 
                    && !Me.ActiveAuras.ContainsKey("Misdirection")
                    && Me.CurrentTarget.ThreatInfo.RawPercent > 75)
                {
                    Lua.DoString("RunMacroText('/cast [@focus,exists] Misdirection');");
                    {
                        Logging.Write(Colors.Aqua, ">> Misdirection on Focus <<");
                        return true;
                    }
                }
            }
            return false;
        }
        #region Trinkets
        public bool UseTrinket1()
        {
            if (SurvivalistSettings.myPrefs.UseTrinket1 == "never") { return false; }
            else if (StyxWoW.Me.Inventory.Equipped.Trinket1 != null && StyxWoW.Me.Inventory.Equipped.Trinket1.Cooldown <= 0 && SurvivalistSettings.myPrefs.UseTrinket1 == "always")
            {
                Lua.DoString("RunMacroText('/use 13');");
                Logger.Write(Colors.Yellow, "Using 1st Trinket");
                return true;
            }
            else if (StyxWoW.Me.Inventory.Equipped.Trinket1 != null && StyxWoW.Me.Inventory.Equipped.Trinket1.Cooldown <= 0 && GeefSajette())
            {
                Lua.DoString("RunMacroText('/use 13');");
                Logger.Write(Colors.Yellow, "Using 1st Trinket");
                return true;
            }
            return false;
        }
        public bool UseTrinket2()
        {
            if (SurvivalistSettings.myPrefs.UseTrinket2 == "never") { return false; }
            else if (StyxWoW.Me.Inventory.Equipped.Trinket2 != null && StyxWoW.Me.Inventory.Equipped.Trinket2.Cooldown <= 0 && SurvivalistSettings.myPrefs.UseTrinket1 == "always")
            {
                Lua.DoString("RunMacroText('/use 14');");
                Logger.Write(Colors.Yellow, "Using 2nd Trinket");
                return true;
            }
            else if (StyxWoW.Me.Inventory.Equipped.Trinket2 != null && StyxWoW.Me.Inventory.Equipped.Trinket2.Cooldown <= 0 && GeefSajette())
            {
                Lua.DoString("RunMacroText('/use 14');");
                Logger.Write(Colors.Yellow, "Using 2nd Trinket");
                return true;
            }
            return false;
        }
        #endregion Trinkets
        #endregion Hunter Skills
        #region CastSpell Method

        public bool CastSpell(string spellName, WoWPlayer target)
        {
            if (SpellManager.CanCast(spellName, target) && !SpellManager.GlobalCooldown && !Me.IsCasting)
            {
                if (target == Me)
                {
                    return false;
                }
                else
                {
                    SpellManager.Cast(spellName, target);
                    return true;
                }
            }
            return false;
        }


        public bool CastSpell(string spellName)
        {
            if (SpellManager.CanCast(spellName) && !SpellManager.GlobalCooldown && !Me.IsCasting)
            {
                SpellManager.Cast(spellName);
                return true;
            }
            return false;
        }

        public bool CastSpell(int spellID)
        {
            if (SpellManager.CanCast(spellID) && !SpellManager.GlobalCooldown && !Me.IsCasting)
            {
                SpellManager.Cast(spellID);
                return true;
            }
            return false;
        }
        #endregion CastSpell Methods

        #region AddCounting
        public static bool Adds()
        {

            List<WoWUnit> mobList = ObjectManager.GetObjectsOfType<WoWUnit>(false).FindAll(unit =>
                unit.Guid != Me.Guid
                && unit.IsAlive
                && unit.IsHostile
                && unit.Attackable
                && !unit.IsTotem
                && !unit.IsFriendly
                && (unit.Location.Distance(Me.CurrentTarget.Location) <= 10 || unit.Location.Distance2D(Me.CurrentTarget.Location) <= 10));

            if (mobList.Count >= SurvivalistSettings.myPrefs.UseAOE)
            {
                return true;
            }
            return false;

        }
         
        private int addCount()
        {
            int count = 0;
            foreach (WoWUnit u in ObjectManager.GetObjectsOfType<WoWUnit>(true, true))
            {
                if (Me.GotTarget
                    && u.IsAlive
                    && u.Guid != Me.Guid
                    && !u.IsFriendly
                    && u.IsHostile
                    && u.Attackable
                    && !u.IsTotem
                    && !u.IsCritter
                    && !u.IsNonCombatPet
                    && (u.Location.Distance(Me.CurrentTarget.Location) <= 10 || u.Location.Distance2D(Me.CurrentTarget.Location) <= 10))
                {
                    count++;
                }
            }
            return count;
        }
        #endregion AddCounting

        #region Racial
        private bool Racial()
        {
            if (SpellManager.CanCast("Blood Fury") && !SpellManager.GlobalCooldown && GeefSajette())
            {
                SpellManager.Cast("Blood Fury");
                Logger.Write("Blood Fury");
                return true;
            }
            if (SpellManager.CanCast("Berserking") && !SpellManager.GlobalCooldown && GeefSajette())
            {
                SpellManager.Cast("Berserking");
                Logger.Write("Berserking");
                return true;
            }
            return false;
        }
        #endregion Racial
         

        #region Movement
        WoWPoint attackPoint
        {
            get
            {
                if (Me.GotTarget && SpellManager.Spells.ContainsKey("Auto Shot"))
                {
                    return WoWMovement.CalculatePointFrom(Me.CurrentTarget.Location, (float)SpellManager.Spells["Auto Shot"].MaxRange - 3);
                }
                else
                {
                    WoWPoint noSpot = new WoWPoint();
                    return noSpot;
                }
            }
        }
        #endregion Movement

        #region Use Bag Item
        private bool HealthStone()
        {
            if (Me.HealthPercent <= SurvivalistSettings.myPrefs.UseHealthStone 
                && !SpellManager.Spells["Healthstone"].Cooldown)
            {
                foreach (WoWItem item in Me.BagItems)
                {
                    if (item != null)
                    {
                        if (item.Name == "Healthstone")
                        {
                            Lua.DoString("RunMacroText(\"/use " + item.Name + "\")");
                            Logger.Write("Using Healthstone");
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        private bool WaterSpirit()
        {
            if (Me.ManaPercent <= SurvivalistSettings.myPrefs.UseWaterSpirit
                && !Me.HasAura("Water Spirit")
                && !Me.HasAura("Life Spirit")
                && !SpellManager.Spells["Water Spirit"].Cooldown)
            {
                foreach (WoWItem item in Me.BagItems)
                {
                    if (item != null)
                    {
                        if (item.Name == "Water Spirit")
                        {
                            Lua.DoString("RunMacroText(\"/use " + item.Name + "\")");
                            Logging.Write(Colors.Yellow, "Using Water Spirit");
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        private bool LifeSpirit()
        {
            if (Me.HealthPercent <= SurvivalistSettings.myPrefs.UseLifeSpirit
                && !Me.HasAura("Water Spirit")
                && !Me.HasAura("Life Spirit")
                && !SpellManager.Spells["Life Spirit"].Cooldown)
            {
                foreach (WoWItem item in Me.BagItems)
                {
                    if (item != null)
                    {
                        if (item.Name == "Life Spirit")
                        {
                            Lua.DoString("RunMacroText(\"/use " + item.Name + "\")");
                            Logging.Write(Colors.Yellow, "Using Life Spirit");
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        #endregion Use Bag Item

        #region Kind of target
        private bool BossOrNot()
        {
            if (Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.WorldBoss || Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.Elite && Me.CurrentTarget.MaxHealth >= SurvivalistSettings.myPrefs.HandleAsBoss)
            {
                return true;
            }
            return false;
        }
        private bool Dummy()
        {
            if (Me.CurrentTarget.CreatureType == WoWCreatureType.Mechanical && Me.CurrentTarget.MaxHealth == 1)
            {
                return true;
            }
            return false;
        }
        private bool Speler()
        {
            if (Me.CurrentTarget.IsPlayer)
            {
                return true;
            }
            return false;
        }

        public bool GeefSajette()
        {
            int targetLvl = Me.CurrentTarget.Level;
            int mijnLvl = Me.Level;
            int LvlVerschil = 0;
            if (targetLvl > mijnLvl) { LvlVerschil = targetLvl - mijnLvl; }
            if (mijnLvl > targetLvl) { LvlVerschil = mijnLvl - targetLvl; }

            if (BossOrNot() || Speler() || Dummy() || Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.Elite && LvlVerschil <= SurvivalistSettings.myPrefs.lvlDiff && (!Me.IsInInstance || !Me.GroupInfo.IsInParty)) return true;
            else return false;
        }
         
        #endregion Kind of Target

        #region Pet
        public bool CallPet()
        {
            StyxWoW.SleepForLagDuration();
            string myPet = SurvivalistSettings.myPrefs.CallMyPet;
            if (SpellManager.CanCast(myPet) && !Me.Mounted)
            {
                if (!petPresenceTimer.IsRunning) { petPresenceTimer.Start(); }
                if (Me.Pet == null)
                {
                    if (petPresenceTimer.ElapsedMilliseconds <= 2000)
                    {
                        SpellManager.Cast(myPet);
                        Logging.Write(Colors.Yellow, myPet);
                        StyxWoW.SleepForLagDuration();
                        return true;
                    }
                }
            }
            return false;
        }
        public bool RevivePet()
        {
            string myPet = SurvivalistSettings.myPrefs.CallMyPet;
            if (petPresenceTimer.ElapsedMilliseconds > 5000 && !Me.GotAlivePet)
            {
                if (SpellManager.CanCast(myPet) && !Me.Mounted && !Me.IsCasting)
                {
                    SpellManager.Cast("Revive Pet");
                    Logging.Write(Colors.Yellow, "Revive Pet");
                    StyxWoW.SleepForLagDuration();
                    petPresenceTimer.Reset();
                    return true;
                }
            }
            return false;
        }
        public bool MendPet()
        {
            if (SpellManager.CanCast("Mend Pet"))
            {
                if (Me.Pet != null && Me.Pet.HealthPercent <= SurvivalistSettings.myPrefs.Mendpet 
                    && !Me.Pet.HasAura("Mend Pet"))
                {
                    SpellManager.Cast("Mend Pet");
                    Logging.Write(Colors.Yellow, "Mend Pet");
                    return true;
                }
            }
            return false;
        }
        #endregion Pet
        #region getNewtarget
		private void GetTarget()
        {
            if (!Me.GotTarget)
            {
                FindTarget();
            }
            else
            {
                if (Me.CurrentTarget.IsPet)
                {
                    (Me.CurrentTarget.CreatedByUnit).Target();
                    BotPoi.Current = new BotPoi(Me.CurrentTarget, PoiType.Kill);
                    WoWMovement.ConstantFace(Me.CurrentTargetGuid);
                }

                if (Me.CurrentTarget.Distance > 30 || !Me.CurrentTarget.IsAlive || !Me.CurrentTarget.Attackable
                    || Me.CurrentTarget.HasAura("Spirit of Redemption") || Me.CurrentTarget.HasAura("Ice Block"))
                {
                    Me.ClearTarget();
                    FindTarget();
                }
            }
        }
        private void FindTarget()
        {
            WoWPlayer newTarget = ObjectManager.GetObjectsOfType<WoWPlayer>(false, false).
                Where(p => p.IsHostile && !p.IsTotem && !p.IsPet && !p.IsDead && p.DistanceSqr <= (10 * 10) && !p.Mounted
                    && !p.HasAura("Ice Block") && !p.HasAura("Spirit of Redemption")).
                OrderBy(u => u.HealthPercent).FirstOrDefault();
            if (newTarget != null)
            {
                newTarget.Target();
                BotPoi.Current = new BotPoi(Me.CurrentTarget, PoiType.Kill);
                WoWMovement.ConstantFace(Me.CurrentTargetGuid);
            }

        }
        #endregion getNewTarget
    } // end public class Survivalist : CombatRoutine
} // end namespace Survivalist
